package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还书籍");

        int currentSize = bookList.getUsedSize();
        System.out.println("请输入你要还的书：");
        Scanner scanner = new Scanner(System.in);

        String name = scanner.nextLine();

        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBooks(i);
            if (book.getName().equals(name)) {
                if (book.isBorrowed()){
                    book.setBorrowed(false);
                    System.out.println("归还成功");

                } else {
                    System.out.println("你没借这本书");
                }
            }
            return;
        }
        System.out.println("这书不是我们的");
    }
}
